﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Setting_Employees : SessionPage
{
    protected int PageSize = 15;
    protected int PageStart = 0;
    protected int PageNum = 1;
    protected int CurPage = 1;

    LogicLayer mgr = new LogicLayer();
    List<SYS_Employee> objList = new List<SYS_Employee>();

	protected string key = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        //检查权限
        this.VerifyFunction("setting");

		key = Request.QueryString["key"] + "";

        //删除人员
        if (!string.IsNullOrEmpty(Request.QueryString["delID"]))
        {
            mgr.DisableEmployee(Request.QueryString["delID"]);
        }

        //得到人员列表
        objList = mgr.FindEmployees(key);

        //分页参数
        if (Request.QueryString["p"] != null)
        {
            try
            {
                CurPage = int.Parse(Request.QueryString["p"]);
            }
            catch { }
        }
        PageStart = (CurPage - 1) * PageSize;
        if (objList != null)
        {
            if (objList.Count % PageSize == 0)
                PageNum = objList.Count / PageSize;
            else
                PageNum = objList.Count / PageSize + 1;
        }
        else
        {
            PageNum = 0;
            PageStart = 0;
        }
    }

    protected void WriteTableData()
    {
        if (objList != null)
        {
            for (int i = PageStart; i < objList.Count && i < PageStart + PageSize; i++)
            {
                Response.Write("<tr>");

                Response.Write("<td nowrap>");
                Response.Write(objList[i].EmplName);
                Response.Write("</td>");

                Response.Write("<td>");
                Response.Write(mgr.GetDeptNameByEmplID(objList[i].EmplID));
                Response.Write("</td>");

                Response.Write("<td>");
                Response.Write(mgr.GetPositionNameByEmplID(objList[i].EmplID));
                Response.Write("</td>");

                Response.Write("<td>" + objList[i].Phone1 + "</td>");
                Response.Write("<td>" + objList[i].Mobile + "</td>");
                Response.Write("<td>" + objList[i].Email + "</td>");

                Response.Write("<td>" + mgr.GetUserNameByEmplID(objList[i].EmplID) + "</td>");

                Response.Write("<td width=\"1%\" nowrap >");
				Response.Write("<a href=\"javascript:editEmpl('" + objList[i].EmplID + "')\">编辑</a>&nbsp;");
				Response.Write("<a href=\"javascript:delEmpl('" + objList[i].EmplID + "')\">删除</a>");
                Response.Write("</td>");

                Response.Write("</tr>");
            }
        }
    }

    protected void WriteTablePager()
    {
        if (PageNum > 0)
        {
            //页码数
            int LinkNum = 10;

            Response.Write("第");

            int PageNumX = 1, CurPageX = 1;
            if (PageNum % LinkNum == 0)
                PageNumX = PageNum / LinkNum;
            else
                PageNumX = PageNum / LinkNum + 1;

            if (CurPage % LinkNum == 0)
                CurPageX = CurPage / LinkNum;
            else
                CurPageX = CurPage / LinkNum + 1;

            if (CurPageX > 1)
                Response.Write("<a href=\"javascript:GoPage(" + (CurPageX - 1) * LinkNum + ")\" ><<</a>");

            for (int j = (CurPageX - 1) * LinkNum + 1; j <= PageNum && j <= CurPageX * LinkNum; j++)
            {
                if (j == CurPage)
                    Response.Write("<a href=\"#\" class=\"curPage\">" + j.ToString() + "</a>");
                else
                    Response.Write("<a href=\"javascript:GoPage(" + j + ")\" >" + j.ToString() + "</a>");
            }
            if (CurPageX < PageNumX)
                Response.Write("<a href=\"javascript:GoPage(" + (CurPageX * LinkNum + 1) + ")\" >>></a>");

            Response.Write("页,共" + PageNum + "页");
        }
    }
}